package com.ybg.user.controller;

import com.ybg.common.entity.Message;
import com.ybg.user.business.entity.InputUser;
import com.ybg.user.business.entity.UserInfo;
import com.ybg.user.business.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "/user", tags = {"用户个人行为"})
@RestController
@RequestMapping("/user")
public class UserSelfController {
    private UserService userService;

    @Autowired
    public UserSelfController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation(value = "/activate",tags = {"首次登录账号激活"})
    @PostMapping("/activate")
    public @ApiResponse(description = "分配账号结果") Message userActivate(
            @ApiParam("提供编号和新密码")
            @ModelAttribute UserInfo userInfo){
        return userService.userActivate(userInfo);
    }

    @ApiOperation(value = "/login",tags = {"登录"})
    @PostMapping("/login")
    public @ApiResponse(description = "登录结果") Message userLogin(
            @ApiParam("提供账号和密码")
            @ModelAttribute InputUser userInfo){
        return userService.userLogin(userInfo);
    }

    public @ApiResponse(description = "员工登录状态") Message employeeLoginState(
            @ApiParam("用户编号")
            @RequestParam("id") int id){
        return userService.getLoginEmployee(id);
    }

    public @ApiResponse(description = "工人登录状态") Message workerLoginState(
            @ApiParam("用户编号")
            @RequestParam("id") int id){
        return userService.getLoginWorker(id);
    }

    @ApiOperation(value = "/cancel",tags = {"注销"})
    @PostMapping("/cancel")
    public @ApiResponse(description = "注销结果") Message userCancel(
            @ApiParam("提供用户编号")
            @RequestParam("userId") int userId){
        return userService.userCancel(userId);
    }


}
